﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Warehouse.DataAccess
{
    public partial class PaymentView : CustomView<PaymentView>
    {
        public static double GetPaidAmount(int supplierId, DateTime endDate)
        {
            using (WarehouseClassesDataContext context = new WarehouseClassesDataContext())
            {
                return (from t in context.PaymentView where t.Status == (int)BillStatus.Default && t.SupplierID == supplierId && t.ReceiptDate < endDate select new { Amount = (double?)t.Amount, IsIncome = t.IsIncome }).Sum(p => p.Amount * (p.IsIncome ? -1d : 1d)) ?? 0d;
            }
        }
    }
}
